import 'package:flutter/cupertino.dart';
import 'package:flutter/widgets.dart';
import '../public.dart';

class LoadingComponent extends StatelessWidget {
  final String text;
  final bool show;
  final Widget child;
  final bool maintainState;
  final Color backgroundColor;
  final EdgeInsets padding;
  final TextStyle testStyle;

  LoadingComponent(
      {Key key,
      this.child = const SizedBox.shrink(),
      this.text = '努力加载中...',
      this.show = true,
      this.maintainState = false,
      this.backgroundColor = Colors.transparent,
      this.padding,
      this.testStyle})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    console(this.show, l1: 3333333);
    return Stack(
      children: [
        Visibility(
            visible: show, maintainState: maintainState, child: buildLoadind()),
        Visibility(maintainState: maintainState, visible: !show, child: child)
      ],
    );
  }

  buildLoadind() {
    return Container(
        alignment: Alignment.center,
        color: backgroundColor,
        padding: padding ?? EdgeInsets.all(0),
        child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              ImagesGif(
                path: AppConfig.ASSETS_PATH + 'loadings',
                duration: Duration(seconds: 2),
                highIndex: 26,
              ),
              SizedBox(height: 8),
              Text(
                text,
                style: testStyle ??
                    TextStyle(color: Color(0x99ffffff), fontSize: 12),
              )
            ]));
  }
}
